package org.cll.lagou.study.ssm.service.impl;

import org.cll.lagou.study.ssm.dao.ResumeDao;
import org.cll.lagou.study.ssm.entity.Resume;
import org.cll.lagou.study.ssm.mapper.ResumeMapper;
import org.cll.lagou.study.ssm.service.ResumeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/6/22 16:15
 */
@Service(value = "japResumeService")
public class JpaResumeServiceImpl implements ResumeService {

    private static final Logger logger = LoggerFactory.getLogger(JpaResumeServiceImpl.class);

    private ResumeDao resumeDao;

    @Autowired
    public JpaResumeServiceImpl(ResumeDao resumeDao) {
        this.resumeDao = resumeDao;
    }

    @Override
    public Resume getById(Long id) {
        logger.info("====== 服务层");
        if (null == resumeDao) {
            logger.info("====== 注入失败");
            return null;
        }
        Optional<Resume> optional = resumeDao.findById(id);
        return optional.orElse(null);
    }

    @Override
    public List<Resume> selectAll() {
        return resumeDao.findAll();
    }

    @Override
    public int addResume(Resume resume) {
        Resume save = resumeDao.save(resume);
        return 1;
    }

    @Override
    public int updateResume(Resume resume) {
        Resume update = resumeDao.save(resume);
        return 1;
    }

    @Override
    public int deleteById(Long id) {
        resumeDao.deleteById(id);
        return 1;
    }
}
